<?php

class Story_Widget_CreateShortStoryController extends
    Engine_Content_Widget_Abstract
{
    public function indexAction()
    {
    	$viewer = Engine_Api::_()->user()->getViewer();
    	$this->view->can_create = Engine_Api::_()->authorization()->isAllowed('story', $viewer, 'create');
    	
    	if (!$this->view->can_create) {
    		return $this->setNoRender();
    	}
    	
    	
    	$this->view->form = $form = new Story_Form_Create_Custom(array(
    			'category' => Story_Model_Category::SHORT_STORY,
    			'tit' => 'Short Story',
    	));
    	
    	$story = null;
    	if( Engine_Api::_()->core()->hasSubject() ) {
    		$story = Engine_Api::_()->core()->getSubject();
    		 
//     		if($story->category_id != Story_Model_Category::SHORT_STORY){
//     			$this->setNoRender();
//     		}

    		if(!$story->canView(Story_Model_Category::SHORT_STORY)){
    			return $this->setNoRender();
    		}

    		$form->title->setValue($story->getTitle());
    		$body = "body_" . $story->category_id;
    		if($form->$body){
    			$form->$body->setValue(strip_tags($story->body));
    		}
    		$form->story_id->setValue($story->getIdentity());
    	}
    	
       
                
    }

}
